<?php
$this->title="当前Cookie信息";
?>
<?php
$mem = memory_get_usage();
$cookie = $_COOKIE;
$mem_bytes = memory_get_usage() - $mem;
echo '<p>占用内存：' . $mem_bytes . ' bytes，字长：' . var_strlen($_COOKIE) . ' bytes，数组递归长度：' . count($_COOKIE, COUNT_RECURSIVE) . '，数组长度：' . count($_COOKIE) . "</p>\n";
echo '<hr/>' . "\n";
$length = 0;
foreach ($_COOKIE as $key => $value)
{
    $key_length = var_strlen($key);
    $value_length = var_strlen($value);
    $length += $key_length + $value_length;
    echo '<p><span style="color:blue">' . '(' . $key_length . ' bytes)' . $key . '</span> => ' . '(' . $value_length . ' bytes)' . htmlspecialchars(var_export($value, true)) . "</p>\n";
}
echo '<p><span style="color:blue">Total: ' . $length . ' bytes</span>' . "</p>\n";

//计算变量$var含有的数字、字符串及数组的字长bytes总和，数组包括key和value字长
function var_strlen($var)
{
    if (is_array($var))
    {
        $result = 0;
        foreach ($var as $key => $value)
        {
            $result += var_strlen($key) + var_strlen($value);
        }
    }
    elseif (is_numeric($var))
    {
        if (is_int($var))
        {
            $result = PHP_INT_SIZE;
        }
        elseif (is_float($var))
        {
            $result = 4;
        }
        else
        {
            $result = 4;	//有待完善
        }
    }
    elseif (is_string($var))
    {
        $result = strlen($var);
    }
    else
    {
        $result = strlen($var);	//有待完善
    }
    return $result;
}
?>